package com.ltmall.api.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ltmall.api.bean.*;
import com.ltmall.api.comm.Path;
import com.ltmall.api.comm.Path.PathType;
import com.ltmall.api.comm.PathUtil;
import com.ltmall.api.comm.TimeUtil;
import com.ltmall.api.entity.*;
import com.ltmall.api.entity.param.GoodsParam;
import com.ltmall.api.manager.*;
import com.ltmall.api.parse.CommentParse;
import com.ltmall.api.parse.GoodsParse;
import com.ltmall.api.util.ImgUtil;
import com.ltmall.api.util.PageUtil;
import com.ltmall.api.util.RemoteUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.sql.Date;
import java.util.*;

@Controller
public class GoodsController {

    /**
     * The vali tag.
     */
    boolean opTag, valiTag;

    /**
     * The goods manager.
     */
    private GoodsManager goodsManager;

    /**
     * The logi manager.
     */
    private LogisticManager logiManager;

    private DirectSupplyManager directSupplyManager;

    private DirectSupplyGoodsManager directSupplyGoodsManager;

    /**
     * 查询用户某团购活动剩余可购买数量
     *
     * @param request
     * @param response
     */
    public void getUserGroupLeftAmount(HttpServletRequest request, HttpServletResponse response) {

        int leftAmount;
        try {
            String userID = request.getParameter("userID");
            String rulesID = request.getParameter("rulesID");

            //【1】查询团购活动限额
            ThGroupBuyingRules rule = goodsManager.groupBuyingRuleGet(Integer.parseInt(rulesID));
            if (rule == null) {
                RemoteUtil.response(response, null, 0, "团购活动不存在");
            } else {
                //【2】查询用户已经购买数量
                int buyingAmount = directSupplyGoodsManager.getUserGroupBuyingAmount(
                        Integer.parseInt(rulesID), Integer.parseInt(userID));

                leftAmount = rule.getGoodsLimitBuy() - buyingAmount;
                RemoteUtil.response(response, leftAmount, 1, "返回成功");
            }

        } catch (NumberFormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            RemoteUtil.response(response, null, 0, "返回失败");
        }
    }

    //检索社区下的商品
    @SuppressWarnings("unchecked")
    public void groupBuyingActivityList(HttpServletRequest request, HttpServletResponse response) {
        int page = 1;
        if (request.getParameter("page") == null
                || Integer.parseInt(request.getParameter("page")) < 1) {
            page = 1;
        }
        String directId = request.getParameter("directId");
        //String groupType = request.getParameter("groupType");
        String groupType = "0";
        PageUtil pageUtil = new PageUtil(page);
        List<ThGroupBuyingRules> rules = (List<ThGroupBuyingRules>) goodsManager
                .groupBuyingActivityList(pageUtil, directId, Integer.parseInt(groupType));
        if (rules != null) {
            for (ThGroupBuyingRules rule : rules) {

                // 团购id
                List<ThGroupBuying> groupList = goodsManager.groupBuyingGroupGet(rule.getId(), 2);
                List<ThJsonGroup> jsonGroupList = new ArrayList<ThJsonGroup>();
                for (ThGroupBuying tgb : groupList) {
                    ThJsonGroup jg = new ThJsonGroup();
                    jg.setCreatedAt(tgb.getCreatedAt());
                    jg.setGroupCaptain(tgb.getGroupCaptain());
                    jg.setGroupJoinPeople(tgb.getGroupJoinPeople());
                    jg.setGroupPeople(tgb.getGroupPeople());
                    jg.setId(tgb.getId());
                    jg.setUserInfo(accountManager.getInfo(tgb.getGroupCaptain()));
                    jsonGroupList.add(jg);
                }
                rule.setGroup(jsonGroupList);

                //默认的sku
                ThSku price = goodsManager.goodsPrice(rule.getGoodsId(), rule.getGoodsFormat());
                if (price == null) {
                    rule.setGoodsOldPrice(1000f); // 原价，float类型
                    rule.setGroupPrice(1000);
                    rule.setSellOut(88);
                    rule.setGoodsStock(999);
                } else {
                    rule.setSku(price);
                    rule.setGoodsOldPrice((float) price.getMarketPrice()); // 原价，float类型
                    rule.setGroupPrice((int) (price.getPrice() * 100));
                    rule.setSellOut(price.getSellout() + price.getFakeSellout());//虚拟销售量+实际销售量
                    rule.setGoodsStock(price.getStock());
                }

                //其他的sku信息
                List<ThSku> prices = goodsManager.getPrice(rule.getGoodsId());
                rule.setPrices(prices);

                //商品历史销量数据
                int goodSaleHisAmount = goodsManager.getGoodSaleHisAmount(rule.getGoodsId());

                int left = 0;//剩余件数
                int sellOutTotal = 0;
                for (ThSku sku : prices) {
                    left += sku.getStock();
                    //sellOutTotal += (sku.getSellout() + sku.getFakeSellout());
                    //sellOutTotal += sku.getSellout();
                    goodSaleHisAmount += sku.getFakeSellout();
                }
                rule.setCurGroupTotal(goodSaleHisAmount);
                rule.setCurGroupLeft(left);

                //参加团购的用户（取10个用户）
                if (!CollectionUtils.isEmpty(groupList)) {
                    ThGroupBuying groupBuying = groupList.get(0);
                    List<?> orderList = goodsManager.groupByingHistoryGet(groupBuying.getId());
                    List<ClientInfo> infoList = new ArrayList<ClientInfo>();
                    int amount = 0;
                    for (int i = 0; i < orderList.size(); i++) {
                        Object[] obj = (Object[]) orderList.get(i);
                        int userId = Integer.parseInt(obj[0].toString());
                        ClientInfo clientInfo = accountManager.getInfo(userId);
                        //小区
                        /* int directId1 = Integer.parseInt(obj[6].toString());
                           ThDirectSupply directSupply = directSupplyManager
                            .getDirectSupplyById(directId1 + "");
                        if (directSupply != null) {
                            clientInfo.setDirectSupply(directSupply.getBlockName());
                        } else {
                            clientInfo.setDirectSupply("");
                        }*/
                        amount += Integer.parseInt(obj[7].toString());
                        clientInfo.setOpTime(Long.valueOf(obj[1].toString()));
                        infoList.add(clientInfo);
                    }
                    rule.setCurGroupSellOut(amount);
                    rule.setClientInfoList(infoList);
                }

            }

            //猜你喜欢
            String goodId = request.getParameter("goodID");
            if (StringUtils.isNotBlank(goodId)) {
                List<ThGroupBuyingRules> rules0 = new ArrayList<ThGroupBuyingRules>();
                for (ThGroupBuyingRules rule : rules) {
                    //排除当前的商品
                    if (rule.getGoodsId() != Integer.parseInt(goodId)) {
                        //添加商品信息
                        Goods goods = goodsManager.goodsDetail(rule.getGoodsId());

                        //阶梯价格
                        if (rule.getIsLadderPrice() == 1) {
                            //执行阶梯价格
                            int groupJoinPeople = 0; //参团人数
                            ThGroupBuying group = goodsManager
                                    .groupBuyingGetByRulesId(rule.getId());
                            //首次开团
                            if (group != null) {
                                groupJoinPeople = group.getGroupJoinPeople();
                            }

                            //判断当前团购人数属于哪个区间
                            double price = 0;
                            if (groupJoinPeople < rule.getLevel2Num()) {
                                price = Double.parseDouble(rule.getSku().getLevel1Price());
                            } else if (groupJoinPeople >= rule.getLevel2Num()
                                    && groupJoinPeople < rule.getLevel3Num()) {
                                price = Double.parseDouble(rule.getSku().getLevel2Price());
                            } else if (groupJoinPeople >= rule.getLevel3Num()) {
                                price = Double.parseDouble(rule.getSku().getLevel3Price());
                            }
                            rule.getSku().setPrice(price);
                            rule.setGroupPrice((int) price * 100);
                        }

                        rule.setGoods(goods);
                        rules0.add(rule);
                    }
                }
                rules = rules0;
            }

            //对rules进行重新排序
            List<ThGroupBuyingRules> rules1 = new ArrayList<ThGroupBuyingRules>();
            List<ThGroupBuyingRules> rules2 = new ArrayList<ThGroupBuyingRules>();
            for (int i = 0; i < rules.size(); i++) {
                ThGroupBuyingRules rule = rules.get(i);
                if (rule.getCurGroupLeft() <= 0) {
                    rules1.add(rule);
                } else {
                    rules2.add(rule);
                }
            }
            rules2.addAll(rules1);

            RemoteUtil.response(response, rules2, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "没有团购");
        }
    }

    //小区团购商品
    public void groupBuyingActivityGet(HttpServletRequest request, HttpServletResponse response) {
        //String groupType = request.getParameter("groupType");
        String groupType = "0";//去掉分类
        ThGroupBuyingActivity activity = goodsManager.groupBuyingActivityGet(Integer
                .parseInt(groupType));
        if (activity == null) {
            RemoteUtil.response(response, null, -1, "返回失败");
        } else {
            RemoteUtil.response(response, activity, 1, "返回成功");
        }
    }

    /**
     * Goods list.
     *
     * @param request  the request
     * @param response the response
     */
    // 获取商品列表
    public void goodsList(HttpServletRequest request, HttpServletResponse response) {
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());
        PageUtil page = new PageUtil(param.getPage());

        /*
         * 先获取省份所在的商店ID 再根据type获取获取商品列表
         */
        // 将省里面的省/市去掉
        int shopID = goodsManager.getShopID(param.getType(), param.getProvince(), param.getCity(),
                param.getCounty());
        if (shopID == 0) {
            RemoteUtil.response(response, null, 0, "无开通店铺");
            return;
        }

        // 取全部店铺的数据
        if (param.getAllShops() == 1) {
            shopID = 0;
        }

        List<?> goodsList = goodsManager.goodsList(shopID, param.getType(), page);
        // 解析一下
        List<JsonGoodsList> returnList = GoodsParse.goodsListParse(goodsList, param.getType(),
                goodsManager);

        RemoteUtil.response(response, returnList, 1, "返回成功");
    }

    // 获取商品列表
    @SuppressWarnings("unchecked")
    public void goodsListGet(HttpServletRequest request, HttpServletResponse response)
            throws UnsupportedEncodingException {
        System.out.println("goodsListGet begin: " + System.currentTimeMillis());
        int type = -1;
        PageUtil page = null;
        String strNumPerPage = request.getParameter("numPerPage");
        String strPage = request.getParameter("page");
        String strType = request.getParameter("type");
        try {
            String province = request.getParameter("province");
            /*province = new String(province.getBytes("ISO-8859-1"), "utf-8");*/
            String city = request.getParameter("city");
            /*if (org.apache.commons.lang.StringUtils.isNotBlank(city))
                city = new String(city.getBytes("ISO-8859-1"), "utf-8");*/
            String country = request.getParameter("county");
            /*if (org.apache.commons.lang.StringUtils.isNotBlank(country))
                country = new String(country.getBytes("ISO-8859-1"), "utf-8");*/
            if (province != null || city != null || country != null) {
                try {
                    int numPerPage = Integer.parseInt(strNumPerPage);
                    //int shopId = goodsManager.shopIdGet(province, city, country);
                    int shopID = new Integer(request.getParameter("shopID"));
                    /*List<Integer> shopIdList = goodsManager.getShopIdByAreaName(province, city,
                        country);*/

                    int numberOfPage = Integer.parseInt((strPage == null ? "0" : strPage));
                    page = new PageUtil(numberOfPage);
                    page.setNumPerPage(numPerPage);
                    List<Goods> goodsList = (List<Goods>) goodsManager.getGoodsListByShopId(shopID,
                            page);
                    /*List<Goods> goodsList = (List<Goods>) goodsManager.goodsListByShopIdList(
                        shopIdList, page);*/

                    goodsManager.convertSkuData(goodsList);

                    for (Goods goods : goodsList) {
                        int temp = Integer.MAX_VALUE;
                        for (ThSku sku : goods.getThSkus()) {
                            if (sku.getHidden() == 0 && sku.getID() < temp) {
                                temp = sku.getID();
                                goods.setFakeSellOut(sku.getFakeSellout());
                                goods.setSellOut(sku.getSellout());
                                goods.setGoodsNumber(sku.getStock());
                            }
                            //董事特权只能享受分润总金额的90%
                            if (sku.getProfitShare() >= 0) {
                                int profitShare = (int) ((sku.getProfitShare()) * 0.9);
                                sku.setProfitShare(profitShare);
                            }
                        }
                    }
                    Object object = JSONObject.toJSON(goodsList);
                    RemoteUtil.response(response, object, 1, "返回成功");
                    return;
                } catch (Exception e) {
                    // TODO: handle exception
                    RemoteUtil.response(response, null, -2, e.getMessage());
                    return;
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }

        try {
            int numberOfPage = Integer.parseInt((strPage == null ? "0" : strPage));
            page = new PageUtil(numberOfPage);
            type = Integer.parseInt(strType);
            int numPerPage = Integer.parseInt(strNumPerPage == null ? "20" : strNumPerPage);
            page.setNumPerPage(numPerPage);
        } catch (Exception e) {
            RemoteUtil.response(response, null, -2, "参数错误");
            return;
        }

        List<?> goodsList = goodsManager.goodsListByType(type, page);
        if (goodsList.size() == 0) {
            RemoteUtil.response(response, null, -1, "没有商品");
            return;
        }
        List<Goods> goodsList1 = goodsManager.convertSkuData((List<Goods>) goodsList);
        System.out.println("goodsListGet return from DAO: " + System.currentTimeMillis());

        //		List<JsonGoodsList> returnList = GoodsParse.goodsListParse(goodsList, type, goodsManager, 1);
        System.out.println("goodsListGet end: " + System.currentTimeMillis());
        for (Goods goods : goodsList1) {
            int temp = Integer.MAX_VALUE;
            for (ThSku sku : goods.getThSkus()) {
                if (sku.getHidden() == 0 && sku.getID() < temp) {
                    temp = sku.getID();
                    goods.setFakeSellOut(sku.getFakeSellout());
                    goods.setSellOut(sku.getSellout());
                    goods.setGoodsNumber(sku.getStock());
                }
                //董事特权只能享受分润总金额的90%
                if (sku.getProfitShare() >= 0) {
                    int profitShare = (int) ((sku.getProfitShare()) * 0.9);
                    sku.setProfitShare(profitShare);
                }
            }
        }
        RemoteUtil.response(response, JSON.toJSON(goodsList1), 1, "返回成功");
        return;
    }

    // 人气单品
    public void topSelloutGoodsListGet(HttpServletRequest request, HttpServletResponse response)
            throws UnsupportedEncodingException {
        PageUtil page = null;
        String strNumPerPage = request.getParameter("numPerPage");
        String strPage = request.getParameter("page");
        String goodsId = request.getParameter("goodsId");
        try {
            int numPerPage = Integer.parseInt(strNumPerPage);
            int directId = new Integer(request.getParameter("directId"));
            int numberOfPage = Integer.parseInt((strPage == null ? "0" : strPage));
            page = new PageUtil(numberOfPage);
            page.setNumPerPage(numPerPage);
            List<Goods> goods = directSupplyGoodsManager.getGoodsByDirectSupply(directId, "0");
            //【2】懂事价格
            for (Goods good : goods) {
                int temp = Integer.MAX_VALUE;
                for (ThSku sku : good.getThSkus()) {
                    if (sku.getHidden() == 0 && sku.getID() < temp) {
                        temp = sku.getID();
                        good.setFakeSellOut(sku.getFakeSellout());
                        good.setSellOut(sku.getSellout());
                        good.setGoodsNumber(sku.getStock());
                    }
                    //董事特权只能享受分润总金额的90%
                    if (sku.getProfitShare() >= 0) {
                        int profitShare = (int) ((sku.getProfitShare()) * 0.9);
                        sku.setProfitShare(profitShare);
                    }
                }
            }

            //过滤商品，“去逛逛”入口需要过滤掉当前商品
            if (StringUtils.isNotBlank(goodsId)) {
                List<Goods> goods1 = new ArrayList<Goods>();
                for (Goods good : goods) {
                    if (good.getGoodsID() != Integer.parseInt(goodsId)) {
                        goods1.add(good);
                    }
                }
                goods = goods1;
            }

            //返回结果
            RemoteUtil.response(response, goods, 1, "返回成功");
            return;
        } catch (Exception e) {
            RemoteUtil.response(response, null, -2, e.getMessage());
            return;
        }

    }

    /**
     * Goods detail.
     *
     * @param request  the request
     * @param response the response
     */
    // 获取商品详情
    public void goodsDetail(HttpServletRequest request, HttpServletResponse response) {
        // TODO 原来是[getServletContext().getRealPath("/")]
        String jsonPath = request.getServletContext().getRealPath("/");// 获取json文件的路径
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());
        Goods goods = goodsManager.goodsDetail(param.getGoodsID());

        if (goods == null) {
            RemoteUtil.response(response, null, 0, "商品不存在");
            return;
        }

        // 向前兼容 iOS APP 旧版本
        float versionNum = 0;
        String versionStr = request.getParameter("v");
        if (versionStr != null && !versionStr.equals("")) {
            versionNum = Float.parseFloat(versionStr);
        }
        if (versionNum < 1.2 && goods.getGoodsType() > 5) {
            goods.setGoodsType(1);
        }

        JsonGoodsDetail returnDetail = new JsonGoodsDetail();
        ActivityPrice ap = null;
        // 这是有规格的商品
        if (param.getFormat() != null) {
            /*
             * 判断商品是否是疯抢商品
             */
            ThSku price = getFormat(param.getGoodsID(), param.getFormat());
            if (price != null) {
                goods.setGoodsOldPrice((float) price.getMarketPrice());
                goods.setGoodsPrice((float) price.getPrice());
                goods.setGoodsFormat(price.getFormat());
            }
            ap = goodsManager.getActivityPrice(param.getGoodsID(), param.getFormat());
            if (ap != null) {
                returnDetail.setActivityGoods(1);// 活动商品标签
                goods.setGoodsPrice(ap.getStartPrice());// 活动价格
                goods.setGoodsOldPrice(ap.getEndPrice());// 还原的价格
                goods.setGoodsNumber(ap.getNumber() - ap.getSellOut());
                // goods.setGoodsNumber(ap.getNumber());
                goods.setGoodsFormat(ap.getFormat());
                goods.setSellOut(ap.getSellOut());// 销量
            }
        } else {
            ap = goodsManager.getActivityPrice(goods.getGoodsID(), goods.getGoodsFormat());
            if (ap != null) {
                returnDetail.setActivityGoods(1);// 活动商品标签
                goods.setGoodsPrice(ap.getStartPrice());// 活动价格
                goods.setGoodsOldPrice(ap.getEndPrice());// 还原的价格
                goods.setGoodsNumber(ap.getNumber());
                goods.setGoodsFormat(ap.getFormat());
                goods.setSellOut(ap.getSellOut());
            }
        }
        System.out.println("销售数据： ======" + goods.getSellOut() + "======");
        // 修改一下图片的路径
        goods.setGoodsPicture(GoodsParse.getAllGoodsPicture(goods.getGoodsPicture()));
        GoodsServer server = goodsManager.goodsServer(param.getGoodsID());

        // 添加商品详情
        returnDetail.setGoods(goods);
        // 添加商品服务
        returnDetail.setGoodsServer(server);
        // 获取商品价格
        List<ThSku> price = goodsManager.getPrice(param.getGoodsID());
        //董事特权只能享受分润总金额的90%
        for (ThSku sku : price) {
            if (sku.getProfitShare() >= 0) {
                int profitShare = (int) ((sku.getProfitShare()) * 0.9);
                sku.setProfitShare(profitShare);
            }
        }
        returnDetail.setPrice(price);

        // 更多图片接口
        String moreURL = Path.ip + Path.projPort
                + "/HomeFlavor/templet/businesstemplet/mGoodsImage.html?goodsID="
                + param.getGoodsID();
        returnDetail.setMoreURL(moreURL);

        // 更多参数
        GoodsMore more = goodsManager.goodsMore(param.getGoodsID());
        returnDetail.setGoodsParam(more);

        // 商店名称
        Shop shop = goodsManager.shopDetail(goods.getShopID());
        returnDetail.setShopName(shop.getShopName());

        // 获取乡味故事
        GoodsStory story = goodsManager.goodsStory(goods.getGoodsID());
        if (story == null) {
            returnDetail.setGoodsStory(null);
        } else if ((story.getStoryPicture() == null)
                && (story.getStoryContent() == null || story.getStoryContent().equals(" ") || story
                .getStoryContent().equals("null"))) {
            returnDetail.setGoodsStory(null);
        } else {
            story.setStoryPicture(Path.nginxServerBusinessDir + Path.STORY + File.separator
                    + story.getStoryPicture());
            returnDetail.setGoodsStory(story);
        }
        // 时令果蔬，获取预付款
        if (goods.getGoodsType() == 3) {
            PrePay pp = goodsManager.getPrepay(goods.getGoodsID());
            returnDetail.setPreapay(pp);
        }

        // 最新的一条评论
        List<?> list = goodsManager.latestComment(param.getGoodsID());
        List<JsonComment> commentList = CommentParse.commentListParse(list);
        if (commentList.size() != 0) {
            returnDetail.setComment(commentList.get(0));
        }

        // 商家ID
        returnDetail.setBussinessID(shop.getBussinessID());
        // 店铺logo
        returnDetail.setShopLogo(Path.nginxServerBusinessDir + Path.SHOP + File.separator
                + Path.LOGO + File.separator + shop.getShopLogo());

        // 获取品牌
        int brandID = goods.getBrandID();
        Brand brand = goodsManager.getBrand(brandID);
        if (brand != null) {
            brand.setBrandLogo(Path.nginxServerBusinessDir + Path.SHOP + File.separator
                    + Path.BRAND + File.separator + brand.getBrandLogo());
            returnDetail.setBrand(brand);
        }

        // 是否收藏
        if (param.getUserID() == 0) {// 没有UserID
            returnDetail.setIsCollection(0);
        } else {
            returnDetail.setIsCollection(goodsManager.isCollection(param.getUserID(),
                    goods.getGoodsID()));
        }

        // 获取商品详情默认回复语句
        AutoReply reply = goodsManager.getAutoReply(shop.getShopID());
        if (reply == null) {
            returnDetail.setAutoReplyMessage("欢迎登陆本店");
        } else {
            // 判断当前时间是否在工作时间段内
            String st = reply.getStartTime();
            String et = reply.getEndTime();

            boolean tag = TimeUtil.inTime(st, et);
            if (tag) {// 当前时间在工作时间之内
                returnDetail.setAutoReplyMessage(reply.getWorkMessage());
            } else {
                returnDetail.setAutoReplyMessage(reply.getOffMessage());
            }
        }

        /**
         * 根据商品的ID获取商品的物流 根据地址判断物流的状态
         */
        int logisticID = goods.getGoodsLogistic();// 物流ID
        LogisticPattern pattern = logiManager.getPattern(logisticID);

        String province = param.getProvince();
        String city = param.getCity();

        String definedWord = pattern.getDefinedWord();
        if (definedWord == null) {
            definedWord = "";
        }

        // province = province.replace("省", "").replace("市", "").replace("区",
        // "");
        // city = city.replace("市", "").replace("区", "");

        LogisticPatternExc exc = logiManager.getPatternExc(logisticID, province, city);
        String logisticMessage;
        String mail = "";
        if (exc == null) {// 以默认模版为准
            // logisticMessage = "地址:" +province+city+";快递方式:商家自定义;"+"商品按重量收费;"
            // logisticMessage =definedWord;
            mail = "运费:" + pattern.getInitFee() + "元";
            // "快递方式:商家自定义;"+"商品按重量收费;"
            // +"首重:"+pattern.getInitKG()+"KG/"
            // "运费:"+pattern.getInitFee()+"元/"
            // +"续重:"+pattern.getAddKG()+"KG/"
            // +"运费:"+pattern.getAddFee()+"元;"
            // +"满"+pattern.getMailFee()+"元包邮;"
            // +"现在下单,"+pattern.getDeliveryTime()+"发货;"

        } else {// 以特殊模版为准
            // logisticMessage = "地址:" +province+city+";快递方式:商家自定义;"+"商品按重量收费;"
            mail = "运费:" + exc.getInitFee() + "元";
            // "快递方式:商家自定义;"+"商品按重量收费;"
            // +"首重:"+exc.getInitKG()+"KG/"
            // "运费:"+exc.getInitFee()+"元/"
            // +"续重:"+exc.getAddKG()+"KG/"
            // +"运费:"+exc.getAddFee()+"元;"
            // +"满"+pattern.getMailFee()+"元包邮;"
            // +"现在下单,"+pattern.getDeliveryTime()+"发货;"
        }

        logisticMessage = definedWord;

        returnDetail.setMail(mail);// 邮费
        returnDetail.setLogistic(logisticMessage);
        int commentNumber = goodsManager.commentNumber(param.getGoodsID());
        // 设置回复人数
        returnDetail.setCommentNumber(commentNumber);
        // 设置城市
        returnDetail.setCity(getJsonCity(shop));

        // 好评率
        if (commentNumber == 0) {
            returnDetail.setGoodsRating("100");
        } else {
            // 获取所有评论的人数
            int goodsComment = goodsManager.goodComment(goods.getGoodsID());
            int commentRating = (goodsComment * 100) / commentNumber;
            returnDetail.setGoodsRating(commentRating + "");
        }

        // 设置评分
        List<?> sco = goodsManager.goodsRating(param.getGoodsID());
        JsonScore score = CommentParse.scoreParse(sco);
        returnDetail.setScore(score);
        RemoteUtil.response(response, returnDetail, 1, "返回成功");
    }

    /**
     * 获取团购商品详情 .
     *
     * @param request  the request
     * @param response the response 增加了团购价、活动的团信息
     */
    public void groupBuyingGoodsGet(HttpServletRequest request, HttpServletResponse response) {
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());
        Goods goods = goodsManager.goodsDetail(param.getGoodsID());

        if (goods == null) {
            RemoteUtil.response(response, null, 0, "商品不存在");
            return;
        }

        JsonGoodsDetail returnDetail = new JsonGoodsDetail();

        // 团购id
        int groupRulesId = Integer.parseInt(request.getParameter("groupRulesId"));
        ThGroupBuyingRules rule = goodsManager.groupBuyingRuleGet(groupRulesId);
        List<ThGroupBuying> groupList = goodsManager.groupBuyingGroupGet(groupRulesId, 1);
        if (!CollectionUtils.isEmpty(groupList)) {
            //添加参团信息
            ThGroupBuying groupBuying = groupList.get(0);
            ThJsonGroup jg = new ThJsonGroup();
            jg.setCreatedAt(groupBuying.getCreatedAt());
            jg.setGroupCaptain(groupBuying.getGroupCaptain());
            jg.setGroupJoinPeople(groupBuying.getGroupJoinPeople());
            jg.setGroupPeople(groupBuying.getGroupPeople());
            jg.setId(groupBuying.getId());
            jg.setUserInfo(accountManager.getInfo(groupBuying.getGroupCaptain()));
            returnDetail.setGroupBuying(jg);

            //条件参团用户信息
            List<?> orderList = goodsManager.groupByingHistoryGet(groupBuying.getId());

            /*List<OrderContent> contentList = orderManager.orderContentList(Integer.parseInt(pdt
                .getOrderID()));*/

            List<ClientInfo> infoList = new ArrayList<ClientInfo>();
            for (int i = 0; i < orderList.size(); i++) {
                Object[] obj = (Object[]) orderList.get(i);
                int userId = Integer.parseInt(obj[0].toString());
                int directId = Integer.parseInt(obj[6].toString());
                ClientInfo clientInfo = accountManager.getInfo(userId);
                //小区
                ThDirectSupply directSupply = directSupplyManager
                        .getDirectSupplyById(directId + "");
                if (directSupply != null) {
                    clientInfo.setDirectSupply(directSupply.getBlockName());
                } else {
                    clientInfo.setDirectSupply("");
                }
                clientInfo.setOpTime(Long.valueOf(obj[1].toString()));
                infoList.add(clientInfo);
            }
            returnDetail.setClientInfoList(infoList);
        }

        returnDetail.setActivityGoods(1);// TODO 活动商品标签 什么意思？
        returnDetail.setActivityID(groupRulesId);
        returnDetail.setActivityName("ThGroupBuyingRules");
        ThSku sku = goodsManager.skuGet(param.getSkuID());
        if (sku != null) {
            goods.setGoodsOldPrice((float) sku.getMarketPrice());
            goods.setGoodsPrice((float) sku.getPrice());
            goods.setGoodsFormat(sku.getFormat());
        }
        System.out.println("销售数据： ======" + goods.getSellOut() + "======");
        // 修改一下图片的路径
        goods.setGoodsPicture(GoodsParse.getAllGoodsPicture(goods.getGoodsPicture()));
        GoodsServer server = goodsManager.goodsServer(param.getGoodsID());

        // 添加团购规则
        returnDetail.setGroupBuyingRule(rule);
        // 添加商品详情
        returnDetail.setGoods(goods);
        // 添加商品服务
        returnDetail.setGoodsServer(server);
        // 获取商品价格
        List<ThSku> price = goodsManager.getPrice(param.getGoodsID());
        returnDetail.setPrice(price);

        int left = 0;//剩余件数
        int sellOutTotal = 0;
        for (ThSku sk : price) {
            left += sk.getStock();
            sellOutTotal = sk.getSellout() + sk.getFakeSellout();
        }
        rule.setCurGroupTotal(sellOutTotal);
        rule.setCurGroupLeft(left);

        // 更多图片接口
        String moreURL = Path.ip + Path.projPort
                + "/HomeFlavor/templet/businesstemplet/mGoodsImage.html?goodsID="
                + param.getGoodsID();
        returnDetail.setMoreURL(moreURL);

        // 更多参数
        GoodsMore more = goodsManager.goodsMore(param.getGoodsID());
        returnDetail.setGoodsParam(more);

        // 商店名称
        Shop shop = goodsManager.shopDetail(goods.getShopID());
        returnDetail.setShopName(shop.getShopName());

        // 获取乡味故事
        GoodsStory story = goodsManager.goodsStory(goods.getGoodsID());
        if (story == null) {
            returnDetail.setGoodsStory(null);
        } else if ((story.getStoryPicture() == null)
                && (story.getStoryContent() == null || story.getStoryContent().equals(" ") || story
                .getStoryContent().equals("null"))) {
            returnDetail.setGoodsStory(null);
        } else {
            story.setStoryPicture(Path.nginxServerBusinessDir + Path.STORY + File.separator
                    + story.getStoryPicture());
            returnDetail.setGoodsStory(story);
        }
        // 时令果蔬，获取预付款
        if (goods.getGoodsType() == 3) {
            PrePay pp = goodsManager.getPrepay(goods.getGoodsID());
            returnDetail.setPreapay(pp);
        }

        // 最新的一条评论
        List<?> list = goodsManager.latestComment(param.getGoodsID());
        List<JsonComment> commentList = CommentParse.commentListParse(list);
        if (commentList.size() != 0) {
            returnDetail.setComment(commentList.get(0));
        }

        // 商家ID
        returnDetail.setBussinessID(shop.getBussinessID());
        // 店铺logo
        returnDetail.setShopLogo(Path.nginxServerBusinessDir + Path.SHOP + File.separator
                + Path.LOGO + File.separator + shop.getShopLogo());

        // 获取品牌
        int brandID = goods.getBrandID();
        Brand brand = goodsManager.getBrand(brandID);
        if (brand != null) {
            brand.setBrandLogo(Path.nginxServerBusinessDir + Path.SHOP + File.separator
                    + Path.BRAND + File.separator + brand.getBrandLogo());
            returnDetail.setBrand(brand);
        }

        // 是否收藏
        if (param.getUserID() == 0) {// 没有UserID
            returnDetail.setIsCollection(0);
        } else {
            returnDetail.setIsCollection(goodsManager.isCollection(param.getUserID(),
                    goods.getGoodsID()));
        }

        // 获取商品详情默认回复语句
        AutoReply reply = goodsManager.getAutoReply(shop.getShopID());
        if (reply == null) {
            returnDetail.setAutoReplyMessage("欢迎登陆本店");
        } else {
            // 判断当前时间是否在工作时间段内
            String st = reply.getStartTime();
            String et = reply.getEndTime();

            boolean tag = TimeUtil.inTime(st, et);
            if (tag) {// 当前时间在工作时间之内
                returnDetail.setAutoReplyMessage(reply.getWorkMessage());
            } else {
                returnDetail.setAutoReplyMessage(reply.getOffMessage());
            }
        }

        /**
         * 根据商品的ID获取商品的物流 根据地址判断物流的状态
         */
        int logisticID = goods.getGoodsLogistic();// 物流ID
        LogisticPattern pattern = logiManager.getPattern(logisticID);

        String province = param.getProvince();
        String city = param.getCity();

        String definedWord = pattern.getDefinedWord();
        if (definedWord == null) {
            definedWord = "";
        }

        LogisticPatternExc exc = logiManager.getPatternExc(logisticID, province, city);
        String logisticMessage;
        String mail = "";
        if (exc == null) {// 以默认模版为准
            mail = "运费:" + pattern.getInitFee() + "元";
        } else {// 以特殊模版为准
            mail = "运费:" + exc.getInitFee() + "元";
        }

        logisticMessage = definedWord;

        returnDetail.setMail(mail);// 邮费
        returnDetail.setLogistic(logisticMessage);
        int commentNumber = goodsManager.commentNumber(param.getGoodsID());
        // 设置回复人数
        returnDetail.setCommentNumber(commentNumber);
        // 设置城市
        returnDetail.setCity(getJsonCity(shop));

        // 好评率
        if (commentNumber == 0) {
            returnDetail.setGoodsRating("100");
        } else {
            // 获取所有评论的人数
            int goodsComment = goodsManager.goodComment(goods.getGoodsID());
            int commentRating = (goodsComment * 100) / commentNumber;
            returnDetail.setGoodsRating(commentRating + "");
        }

        // 设置评分
        List<?> sco = goodsManager.goodsRating(param.getGoodsID());
        JsonScore score = CommentParse.scoreParse(sco);
        returnDetail.setScore(score);

        RemoteUtil.response(response, returnDetail, 1, "返回成功");
    }

    /**
     * Gets the json city.
     *
     * @param shop the shop
     * @return the json city
     */
    public JsonCity getJsonCity(Shop shop) {
        BussinessInfo bInfo = goodsManager.getBussinessInfo(shop.getBussinessID());
        JsonCity jCity = new JsonCity();
        jCity.setProvince(bInfo.getCompanyProvince());
        jCity.setCity(bInfo.getCompanyCity());
        jCity.setCounty(bInfo.getCompanyCounty());
        return jCity;
    }

    /**
     * Remind.
     *
     * @param request  the request
     * @param response the response
     */
    // 设置提醒
    public void remind(HttpServletRequest request, HttpServletResponse response) {
        String goodsID = request.getParameter("goodsID");
        String type = request.getParameter("type");

        opTag = goodsManager.remind(Integer.parseInt(goodsID), Integer.parseInt(type));
        if (opTag) {
            RemoteUtil.response(response, null, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    /**
     * Gets the format.
     *
     * @param goodsID the goods ID
     * @param format  the format
     * @return the format
     */
    // 修改format
    public ThSku getFormat(int goodsID, String format) {
        List<ThSku> priceList = goodsManager.getPrice(goodsID);
        for (ThSku price : priceList) {
            if (price.getFormat().equals(format)) {
                return price;
            }
        }
        return null;
    }

    /**
     * Comment list.
     *
     * @param request  the request
     * @param response the response
     */
    // 评论列表
    public void commentList(HttpServletRequest request, HttpServletResponse response) {
        String goodsID = request.getParameter("goodsID");
        int cPage = Integer.parseInt(request.getParameter("page"));
        PageUtil page = new PageUtil(cPage);

        List<?> commentList = goodsManager.commentList(Integer.parseInt(goodsID), page);
        List<JsonComment> returnList = CommentParse.commentListParse(commentList);
        RemoteUtil.response(response, returnList, 1, "返回成功");

    }

    /**
     * Top.
     *
     * @param request  the request
     * @param response the response
     */
    // 人气榜单
    public void top(HttpServletRequest request, HttpServletResponse response) {
        String province = request.getParameter("province");
        String city = request.getParameter("city");
        String county = request.getParameter("county");
        String pageNumber = request.getParameter("page");
        if (pageNumber == null) {
            pageNumber = "0";
        }
        PageUtil page = new PageUtil(Integer.parseInt(pageNumber));

        List<Goods> hotGoods = goodsManager.hotGoods(province, city, county, page);

        for (Goods goods : hotGoods) {// 设置图片
            goods.setGoodsPicture(GoodsParse.getOneGoodsPicture(goods.getGoodsPicture()));
        }

        RemoteUtil.response(response, hotGoods, 1, "返回成功");
    }

    /**
     * Popular goods get.
     *
     * @param request  the request
     * @param response the response
     */
    // 新的人气单品
    public void popularGoodsGet(HttpServletRequest request, HttpServletResponse response) {
        String province = request.getParameter("province");
        String city = request.getParameter("city");
        String county = request.getParameter("county");
        String p = (request.getParameter("page") == null || request.getParameter("page").equals("")) ? "1"
                : request.getParameter("page");
        int cPage = Integer.parseInt(p);
        cPage = cPage > 0 ? cPage : 1;
        PageUtil page = new PageUtil(cPage);
        page.setNumPerPage(30);
        List<Goods> hotGoods = goodsManager.popularGoodsGet(province, city, county, page);

        for (Goods goods : hotGoods) {// 设置图片
            goods.setGoodsPicture(GoodsParse.getOneGoodsPicture(goods.getGoodsPicture()));
        }

        RemoteUtil.response(response, hotGoods, 1, "返回成功");
    }

    // 超值量贩
    public void wholesaleGoodsGet(HttpServletRequest request, HttpServletResponse response) {
        String province = request.getParameter("province");
        String city = request.getParameter("city");
        String county = request.getParameter("county");

        String goodsType = request.getParameter("goodsType");
        int type = Integer.parseInt((request.getParameter("type") == null ? "0" : request
                .getParameter("type")));
        int page = Integer.parseInt((request.getParameter("page") == null ? "0" : request
                .getParameter("page")));
        PageUtil pageUtil = new PageUtil(page);
        // 首先取出当前家乡的量贩 ,然后周边城市的量贩，最后总店的量贩
        List<Goods> wholesaleGoods = goodsManager.wholesaleGoodsGet(goodsType, province, city,
                county, type, pageUtil);
        for (Goods goods : wholesaleGoods) {// 设置图片
            goods.setGoodsPicture(GoodsParse.getOneGoodsPicture(goods.getGoodsPicture()));
        }
        List<Goods> goodsList = goodsManager.convertSkuData(wholesaleGoods);
        for (Goods goods : goodsList) {
            int temp = Integer.MAX_VALUE;
            for (ThSku sku : goods.getThSkus()) {
                if (sku.getHidden() == 0 && sku.getID() < temp) {
                    temp = sku.getID();
                    goods.setFakeSellOut(sku.getFakeSellout());
                    goods.setSellOut(sku.getSellout());
                    goods.setGoodsNumber(sku.getStock());
                }
                //董事特权只能享受分润总金额的90%
                if (sku.getProfitShare() >= 0) {
                    int profitShare = (int) ((sku.getProfitShare()) * 0.9);
                    sku.setProfitShare(profitShare);
                }
            }
        }
        RemoteUtil.response(response, goodsList, 1, "返回成功");
    }

    /**
     * Version.
     *
     * @param request  the request
     * @param response the response
     */
    // 版本控制
    public void version(HttpServletRequest request, HttpServletResponse response) {
        int versionCode = 6;
        String versionName = "V_1.1.5.apk";// 当前版本

        String upgradeContent = "修改了注册界面，体验更好;优化了加载线程，系统更加流畅;";
        Version version = new Version();

        version.setVersionName(versionName);
        version.setVersionCode(versionCode);// 版本
        version.setForceUpgrade(0);// 是否强制升级
        version.setUpgradeContent(upgradeContent);// 升级内容
        version.setIOSURL("");// IOSappstore下载地址
        version.setLoadType(1);
        // version.setAndroidURL("ftp://www.xiangweihui.com/"
        // +cVersion);//Android下载链接
        version.setAndroidURL("http://www.xiangweihui.com/APKLoad?apkName=" + versionName);// Android下载链接

        RemoteUtil.response(response, version, 1, "返回成功");
    }

    /**
     * Hot city.
     *
     * @param request  the request
     * @param response the response
     */
    // 新开通的城市
    public void hotCity(HttpServletRequest request, HttpServletResponse response) {
        List<HotCity> fiveCityList = goodsManager.fiveHotCity();
        String cityPath = Path.nginx_server_dir_platform + Path.HOTCITY + File.separator;
        for (HotCity city : fiveCityList) {
            city.setPicture(cityPath + city.getPicture());
        }
        RemoteUtil.response(response, fiveCityList, 1, "返回成功");
    }

    /**
     * City recommend.
     *
     * @param request  the request
     * @param response the response
     */
    // 推荐城市
    public void cityRecommend(HttpServletRequest request, HttpServletResponse response) {
        String cityName = request.getParameter("city");
        String countyName = request.getParameter("county");
        if (cityName != null) {
            List<HotCity> recommendCityList = goodsManager.recommentCityList(cityName, countyName);
            String cityPath = Path.nginx_server_dir_platform + Path.HOTCITY + File.separator;
            for (HotCity city : recommendCityList) {
                city.setPicture(cityPath + city.getPicture());
            }
            RemoteUtil.response(response, recommendCityList, 1, "返回成功");
        } else {
            RemoteUtil.response(response, "", -1, "缺少参数");
        }
    }

    // 推荐城市-wechat
    public void cityRecommendListGet(HttpServletRequest request, HttpServletResponse response) {
        String cityName = request.getParameter("city");
        String countyName = request.getParameter("county");
        if (cityName != null && countyName != null) {
            List<?> recommendCityList = goodsManager.recommentCityListGet(cityName, countyName);
            String posterPath = Path.nginxServerBusinessDir + Path.SHOP + File.separator
                    + Path.LOGO + File.separator;
            List<ThJsonRecommentCity> list = new ArrayList<ThJsonRecommentCity>();
            int num = recommendCityList.size();
            for (int i = 0; i < num; i++) {
                Object[] ob = (Object[]) recommendCityList.get(i);
                String province = ob[0].toString();
                String city = ob[1].toString();
                String county = ob[2].toString();
                String poster = posterPath + (ob[3] == null ? "" : ob[3].toString());
                String englishCityName = (ob[4] == null ? "" : ob[4].toString());
                ThJsonRecommentCity recommendCity = new ThJsonRecommentCity();
                recommendCity.setCity(city);
                recommendCity.setPoster(poster);
                recommendCity.setProvince(province);
                recommendCity.setCounty(county);
                recommendCity.setEnglishCityName(englishCityName);
                list.add(recommendCity);
            }
            RemoteUtil.response(response, list, 1, "返回成功");
        } else {
            RemoteUtil.response(response, "", -1, "缺少参数");
        }
    }

    /**
     * Brand goods.
     *
     * @param request  the request
     * @param response the response
     */
    // 品牌商品
    public void brandGoods(HttpServletRequest request, HttpServletResponse response) {
        String brandID = request.getParameter("brandID");
        String type = request.getParameter("type");
        String page = request.getParameter("page");
        List<?> list = goodsManager.brandGoods(Integer.parseInt(brandID), Integer.parseInt(type),
                new PageUtil(Integer.parseInt(page)));
        List<JsonOtherGoods> returnList = GoodsParse.otherGoodsListParse(list);
        RemoteUtil.response(response, returnList, 1, "返回成功");
    }

    /**
     * Checks if is city open.
     *
     * @param request  the request
     * @param response the response
     */
    // 判断城市是否开通
    public void isCityOpen(HttpServletRequest request, HttpServletResponse response) {
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());
        if (param.getCounty() == null || param.getCity() == null) {
            RemoteUtil.response(response, null, 0, "城市未开通");
            return;
        }
        List<Integer> list = goodsManager.getShopID(param.getProvince(), param.getCity(),
                param.getCounty());
        if (list.size() == 0) {
            RemoteUtil.response(response, null, 0, "城市未开通");
        } else {
            RemoteUtil.response(response, null, 1, "城市已经开通");
        }
    }

    /**
     * Pin goods.
     *
     * @param request  the request
     * @param response the response
     */
    // 凑单商品
    public void pinGoods(HttpServletRequest request, HttpServletResponse response) {
        // 待拼单商品ID
        String goodsID = request.getParameter("goodsID");
        String shopID = request.getParameter("shopID");
        String page = request.getParameter("page");
        int goodsLogistic;

        /*
         * 先根据shopID获取商家ID 获取和商家在同一个圈子的商家 查询商家列表
         */
        Shop shop = goodsManager.shopDetail(Integer.parseInt(shopID));

        // 获取商家所在的圈子
        List<StoreHouse> houseList = goodsManager.getStoreHouses(shop.getShopID());
        List<Integer> shopIDList = new ArrayList<Integer>();

        for (StoreHouse house : houseList) {
            Shop s = goodsManager.shopByBussiness(house.getUserID());
            shopIDList.add(s.getShopID());
        }

        if (shopIDList.size() == 0) {// 表示没有加入圈子
            shopIDList.add(Integer.parseInt(shopID));
        }

        // 判断是否有商品ID，没有则不传，走原来的逻辑
        if (goodsID != null) {
            // 根据商品ID获取商品信息
            Goods goodsDetail = goodsManager.goodsDetail(Integer.parseInt(goodsID));
            if (goodsDetail == null) {
                RemoteUtil.response(response, null, -1, "商品不存在");
            }
            goodsLogistic = goodsDetail.getGoodsLogistic();
        } else {
            goodsLogistic = 0;
        }

        List<?> pinList = goodsManager.pingGoods(shopIDList, goodsLogistic,
                new PageUtil(Integer.parseInt(page)));
        List<JsonGoodsList> returnList = GoodsParse.goodsListParse(pinList, 0, goodsManager);

        RemoteUtil.response(response, returnList, 1, "返回成功");
    }

    /**
     * Ads.
     *
     * @param request  the request
     * @param response the response
     */
    // 获取广告
    public void ads(HttpServletRequest request, HttpServletResponse response) {
        int type = 0;
        String typeStr = request.getParameter("type");
        if (typeStr != null && !typeStr.equals("")) {
            type = Integer.parseInt(typeStr);
        }

        int defaultNumber = 7;// 默认情况下值返回七张广告
        // 广告城市的路径
        String path = Path.nginx_server_dir_platform + Path.ADS + File.separator;
        List<ADS> adsList = goodsManager.ads(type, defaultNumber);
        for (ADS ads : adsList) { // 修改一下图片的地址
            ads.setPicture(path + ads.getPicture());
        }

        /*
         * 首页返回 1：广告 2：通知 3：四张模块图的链接
         */

        List<Broadcast> castList = goodsManager.castList();
        ModelPicture model = goodsManager.getModelPicture();

        if (model != null) {
            model.setaPicture(Path.nginx_server_dir_platform + Path.MODEL + File.separator
                    + model.getaPicture());
            model.setbPicture(Path.nginx_server_dir_platform + Path.MODEL + File.separator
                    + model.getbPicture());
            model.setcPicture(Path.nginx_server_dir_platform + Path.MODEL + File.separator
                    + model.getcPicture());
            model.setdPicture(Path.nginx_server_dir_platform + Path.MODEL + File.separator
                    + model.getdPicture());
            // RemoteUtil.responseJson(response, model);//操作成功
        }

        JsonFirstPageParam param = new JsonFirstPageParam();
        param.setAdsList(adsList);// 广告列表
        param.setBroadcastList(castList);// 广播列表
        param.setModelPicture(model);// 模块图列表

        RemoteUtil.response(response, param, 1, "返回成功");
    }

    // 获取Wechat的banner
    public void bannerListGet(HttpServletRequest request, HttpServletResponse response) {
        List<ThBanners> list = goodsManager.bannerListGet();

        if (list != null) {
            for (ThBanners banner : list) {// 修改一下图片的地址
                banner.setImage(Path.nginx_server_dir_platform + Path.MODEL + File.separator
                        + banner.getImage());
            }
            RemoteUtil.response(response, list, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    /**
     * Shop ADS.
     *
     * @param request  the request
     * @param response the response
     */
    // 商家广告
    public void shopADS(HttpServletRequest request, HttpServletResponse response) {
        int defaultNumber = 5;// 默认情况下值返回三张广告
        // 商家广告的路径
        String path = Path.nginxServerBusinessDir + Path.ADS + File.separator;
        // 根据省市县获取商品名称
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());
        List<BussinessADS> adsList = new ArrayList<BussinessADS>();

        if (param.getType() == 1 || param.getType() == 2 || param.getType() == 3) {
            param.setType(1);
        } else {
            param.setType(2);
            param.setCounty(null);
        }

        int bussinessID = goodsManager.getBussiness(param.getProvince(), param.getCity(),
                param.getCounty(), param.getType());
        if (bussinessID == 0) {// 没有入住商家
            RemoteUtil.response(response, null, 1, "返回成功");
            return;
        }
        adsList = goodsManager.shopADS(defaultNumber, bussinessID);
        for (BussinessADS ads : adsList) {// 修改一下图片的地址
            ads.setPicture(path + ads.getPicture());
        }
        RemoteUtil.response(response, adsList, 1, "返回成功");
    }

    // 商家广告--微商城
    public void wxShopADS(HttpServletRequest request, HttpServletResponse response) {
        int defaultNumber = 5;// 默认情况下值返回三张广告
        // 商家广告的路径
        String path = Path.nginxServerBusinessDir + Path.ADS + File.separator;
        // 根据省市县获取商品名称
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());
        List<BussinessADS> adsList = new ArrayList<BussinessADS>();

        param.setType(1);

        int bussinessID = goodsManager.getBussiness(param.getProvince(), param.getCity(),
                param.getCounty(), param.getType());
        if (bussinessID == 0) {// 没有入住商家
            RemoteUtil.response(response, null, 1, "返回成功");
            return;
        }
        adsList = goodsManager.shopADS(defaultNumber, bussinessID);
        for (BussinessADS ads : adsList) {// 修改一下图片的地址
            ads.setPicture(path + ads.getPicture());
        }
        RemoteUtil.response(response, adsList, 1, "返回成功");
    }

    /**
     * Activity goods.
     *
     * @param request  the request
     * @param response the response
     */
    // 活动商品
    public void activityGoods(HttpServletRequest request, HttpServletResponse response) {
        /*
         * 先判断是否在活动组
         */
        long startTime, endTime;
        Activity activity = goodsManager.latestActivity();

        JsonActivityGoods activityGoods = new JsonActivityGoods();
        List<JsonActivityGoodsContent> goodsDetail = new ArrayList<JsonActivityGoodsContent>();

        if (activity != null) {
            startTime = activity.getStartTime();
            endTime = activity.getEndTime();
            String content = activity.getContent();

            String[] contentArr = content.split(";");
            for (String co : contentArr) {
                String goodsID = co.split(",")[0];
                String activityPrice = co.split(",")[1];
                String goodsFormat = co.split(",")[2];
                String limit = co.split(",")[3];

                ThSku gp = goodsManager.goodsPrice(Integer.parseInt(goodsID), goodsFormat);
                if (gp == null) {
                    continue;
                }

                JsonActivityGoodsContent goodsContent = new JsonActivityGoodsContent();
                Goods goods = goodsManager.goodsDetail(Integer.parseInt(goodsID));
                goodsContent.setGoodsID(goods.getGoodsID());
                goodsContent.setGoodsName(goods.getGoodsName());
                goodsContent.setPrice(goods.getGoodsPrice());
                goodsContent.setActivityPrice(Float.parseFloat(activityPrice));
                goodsContent.setGoodsPic(GoodsParse.getOneGoodsPicture(goods.getGoodsPicture()));
                goodsContent.setGoodsFormat(goodsFormat);

                goodsContent.setGoodsTitle(goods.getGoodsTitle());
                goodsContent.setGoodsLabel(goods.getGoodsLabel());

                goodsContent.setActivityID(activity.getActivityID());
                goodsContent.setActivityName("ThPanicBuyingSku");

                goodsContent.setPercent(0);
                ActivityPrice ap = goodsManager.getActivityPrice(activity.getActivityID(),
                        Integer.parseInt(goodsID), goodsFormat);
                if (ap != null) {
                    int percent = (int) (ap.getSellOut() * 100 / (ap.getNumber() + ap.getSellOut()));
                    if (percent > 100) {
                        percent = 100;
                    }
                    goodsContent.setPercent(percent);
                }

                goodsContent.setLimit(Integer.parseInt(limit));
                // goodsContent.setActivityPrice(activityPrice);
                goodsDetail.add(goodsContent);
            }
            activityGoods.setStartTime(startTime);
            activityGoods.setEndTime(endTime);
            activityGoods.setGoodsList(goodsDetail);
        }
        RemoteUtil.response(response, activityGoods, 1, "操作成功");
    }

    // 获取商品详情
    public void goodsGet(HttpServletRequest request, HttpServletResponse response) {

        long startTime = System.currentTimeMillis();
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());

        //【1】商品的基本信息
        //【1.1】获取商品详情信息
        Goods goods = goodsManager.goodsDetail(param.getGoodsID());
        if (goods == null) {
            RemoteUtil.response(response, null, 0, "商品不存在");
            return;
        }

        //【1.2】 该商品是否参与活动
        JsonGoodsDetail returnDetail = new JsonGoodsDetail();
        returnDetail.setActivityGoods(0);// 活动商品标签
        if (request.getParameter("activityID") != null
                && Integer.parseInt(request.getParameter("activityID")) > 0) {
            //判断商品是否是疯抢商品
            ActivityPrice ap = goodsManager.getActivityPrice(
                    Integer.parseInt(request.getParameter("activityID")), param.getGoodsID(),
                    param.getFormat());
            if (ap != null) {
                returnDetail.setActivityID(ap.getActivityID());// 活动id
                returnDetail.setActivityName("ThPanicBuyingSku");
                returnDetail.setActivityGoods(1);// 活动商品标签
                goods.setGoodsPrice(ap.getStartPrice());// 活动价格
                goods.setGoodsOldPrice(ap.getEndPrice());// 还原的价格
                goods.setGoodsNumber(ap.getNumber());
                // goods.setGoodsNumber(ap.getNumber());
                goods.setGoodsFormat(ap.getFormat());
                goods.setSellOut(ap.getSellOut());// 销量
            } else {
                ThSku price = getFormat(param.getGoodsID(), param.getFormat());
                if (price != null) {
                    goods.setGoodsOldPrice((float) price.getMarketPrice());
                    goods.setGoodsPrice((float) price.getPrice());
                    goods.setGoodsFormat(price.getFormat());
                }
            }
        }
        System.out.println("销售数据： ======" + goods.getSellOut() + "======");
        // 修改一下图片的路径
        goods.setGoodsPicture(PathUtil.getPicPaths(goods.getGoodsPicture(), Path.GOODS));
        returnDetail.setGoods(goods);

        //【1.3】 获取商品价格
        List<ThSku> price = goodsManager.getPrice(param.getGoodsID());
        int temp = Integer.MAX_VALUE;
        for (ThSku sku : price) {
            if (sku != null && sku.getID() < temp) {
                temp = sku.getID();
                goods.setFakeSellOut(sku.getFakeSellout());
                goods.setSellOut(sku.getSellout());
                goods.setGoodsNumber(sku.getStock());
            }
            //董事特权只能享受分润总金额的90%
            if (sku.getProfitShare() >= 0) {
                int profitShare = (int) ((sku.getProfitShare()) * 0.9);
                sku.setProfitShare(profitShare);
            }
        }
        returnDetail.setPrice(price);

        //【1.4】 更多图片接口
        String moreURL = Path.ip + Path.projPort
                + "/HomeFlavor/templet/businesstemplet/mGoodsImage.html?goodsID="
                + param.getGoodsID();
        returnDetail.setMoreURL(moreURL);

        //【1.5】 时令果蔬，获取预付款
        if (goods.getGoodsType() == 3) {
            PrePay pp = goodsManager.getPrepay(goods.getGoodsID());
            returnDetail.setPreapay(pp);
        }

        //【2】获取商品附加信息
        //【2.1】 商店名称（保留）
        Shop shop = goodsManager.shopDetail(goods.getShopID());
        returnDetail.setShopName(shop.getShopName());
        returnDetail.setBussinessID(shop.getBussinessID());// 商家ID
        returnDetail.setShopLogo(Path.nginxServerBusinessDir + Path.SHOP + File.separator
                + Path.LOGO + File.separator + shop.getShopLogo());// 店铺logo

        System.out.println("goodsController spendTime:" + (System.currentTimeMillis() - startTime));
        RemoteUtil.response(response, returnDetail, 1, "返回成功");
    }

    // 获取商品附加信息
    public void goodsExt1Get(HttpServletRequest request, HttpServletResponse response) {

        long startTime = System.currentTimeMillis();
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());
        JsonGoodsDetail returnDetail = new JsonGoodsDetail();

        //【1】商品的基本信息
        //【1.1】获取商品详情信息
        Goods goods = goodsManager.goodsDetail(param.getGoodsID());
        if (goods == null) {
            RemoteUtil.response(response, null, 0, "商品不存在");
            return;
        }

        //【2】获取商品附加信息
        //【2.1】 商店名称（保留）
        /*Shop shop = goodsManager.shopDetail(goods.getShopID());
        returnDetail.setShopName(shop.getShopName());
        returnDetail.setBussinessID(shop.getBussinessID());// 商家ID
        returnDetail.setShopLogo(Path.nginxServerBusinessDir + Path.SHOP + File.separator
                                 + Path.LOGO + File.separator + shop.getShopLogo());// 店铺logo
        */
        //【2.4】根据商品的ID获取商品的物流 根据地址判断物流的状态
        int logisticID = goods.getGoodsLogistic();// 物流ID
        LogisticPattern pattern = logiManager.getPattern(logisticID);
        String definedWord = pattern.getDefinedWord();
        if (definedWord == null) {
            definedWord = "";
        }
        returnDetail.setLogistic(definedWord);

        //【2.5】邮费
        String mail = "";
        LogisticPatternExc exc = logiManager.getPatternExc(logisticID, param.getProvince(),
                param.getCity());
        if (exc == null) {// 以默认模版为准
            mail = "运费:" + pattern.getInitFee() + "元";
        } else {// 以特殊模版为准
            mail = "运费:" + exc.getInitFee() + "元";
        }
        returnDetail.setMail(mail);// 邮费
        System.out.println("goodsExt1Get spendTime:" + (System.currentTimeMillis() - startTime));
        RemoteUtil.response(response, returnDetail, 1, "返回成功");
    }

    // 获取商品附加信息
    public void goodsExt2Get(HttpServletRequest request, HttpServletResponse response) {

        long startTime = System.currentTimeMillis();
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());
        JsonGoodsDetail returnDetail = new JsonGoodsDetail();

        //【2.2】最新的一条评论（这个sql比较复杂）
        List<?> list = goodsManager.latestComment(param.getGoodsID());
        List<JsonComment> commentList = CommentParse.commentListParse(list);
        if (commentList.size() != 0) {
            returnDetail.setComment(commentList.get(0));
        }

        //【2.3】是否收藏
        if (param.getUserID() == 0) {// 没有UserID
            returnDetail.setIsCollection(0);
        } else {
            returnDetail.setIsCollection(goodsManager.isCollection(param.getUserID(),
                    param.getGoodsID()));
        }

        //【5】获取商品服务信息(保留)
        GoodsServer server = goodsManager.goodsServer(param.getGoodsID());
        returnDetail.setGoodsServer(server);

        //【6】获取品牌(去掉)
        /*int brandID = goods.getBrandID();
        Brand brand = goodsManager.getBrand(brandID);
        if (brand != null) {
            brand.setBrandLogo(Path.nginxServerBusinessDir + Path.SHOP + File.separator
                               + Path.BRAND + File.separator + brand.getBrandLogo());
            returnDetail.setBrand(brand);
        }*/

        //【7】 获取乡味故事
        /*GoodsStory story = goodsManager.goodsStory(goods.getGoodsID());
        if (story == null) {
            returnDetail.setGoodsStory(null);
        } else if ((story.getStoryPicture() == null)
                   && (story.getStoryContent() == null || story.getStoryContent().equals(" ") || story
                       .getStoryContent().equals("null"))) {
            returnDetail.setGoodsStory(null);
        } else {
            story.setStoryPicture(Path.nginxServerBusinessDir + Path.STORY + File.separator
                                  + story.getStoryPicture());
            returnDetail.setGoodsStory(story);
        }*/

        //【8】 更多参数（保留）
        GoodsMore more = goodsManager.goodsMore(param.getGoodsID());
        returnDetail.setGoodsParam(more);
        System.out.println("goodsExt2Get spendTime:" + (System.currentTimeMillis() - startTime));

        RemoteUtil.response(response, returnDetail, 1, "返回成功");
    }

    // 获取商品附加信息
    public void goodsExt3Get(HttpServletRequest request, HttpServletResponse response) {

        long startTime = System.currentTimeMillis();
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());
        JsonGoodsDetail returnDetail = new JsonGoodsDetail();

        //后期考虑删除的信息
        //【2】回复人数和城市
        int commentNumber = goodsManager.commentNumber(param.getGoodsID());
        returnDetail.setCommentNumber(commentNumber); // 设置回复人数

        //【3】好评率
        if (commentNumber == 0) {
            returnDetail.setGoodsRating("100");
        } else {
            // 获取所有评论的人数
            int goodsComment = goodsManager.goodComment(param.getGoodsID());
            int commentRating = (goodsComment * 100) / commentNumber;
            returnDetail.setGoodsRating(commentRating + "");
        }
        //【4】设置评分(去掉)
        List<?> sco = goodsManager.goodsRating(param.getGoodsID());
        JsonScore score = CommentParse.scoreParse(sco);
        returnDetail.setScore(score);

        System.out.println("goodsExt3Get spendTime:" + (System.currentTimeMillis() - startTime));
        RemoteUtil.response(response, returnDetail, 1, "返回成功");
    }

    /**
     * Join buying group.
     *
     * @param request  the request userID 用户ID groupID 团的ID skuID 团购商品的skuID num
     *                 团购商品的数目
     * @param response the response
     */
    public void joinGroupBuying(HttpServletRequest request, HttpServletResponse response) {
        int userID = Integer.parseInt(request.getParameter("userID"));
        int groupID = Integer.parseInt(request.getParameter("groupID"));
        int skuID = Integer.parseInt(request.getParameter("skuID"));
        int num = Integer.parseInt(request.getParameter("num"));

        boolean ret = goodsManager.joinGroupBuyingGoup(userID, groupID, skuID, num);
        if (ret) {
            RemoteUtil.response(response, "", 1, "加入成功");
        } else {
            RemoteUtil.response(response, "", 1, "加入失败");
        }
    }

    /**
     * 获取团购的团列表.
     *
     * @param request  the request
     * @param response the response
     */
    public void groupBuyingGroupRulesListGet(HttpServletRequest request,
                                             HttpServletResponse response) {
        int page = 1;
        if (request.getParameter("page") == null
                || Integer.parseInt(request.getParameter("page")) < 1) {
            page = 1;
        }
        PageUtil pageUtil = new PageUtil(page);
        List<ThGroupBuyingRules> rules = goodsManager.groupBuyingGroupRulesGet(pageUtil);
        if (rules != null) {
            for (ThGroupBuyingRules rule : rules) {

                // 团购id
                List<ThGroupBuying> groupList = goodsManager.groupBuyingGroupGet(rule.getId(), 2);
                List<ThJsonGroup> jsonGroupList = new ArrayList<ThJsonGroup>();
                for (ThGroupBuying tgb : groupList) {
                    ThJsonGroup jg = new ThJsonGroup();
                    jg.setCreatedAt(tgb.getCreatedAt());
                    jg.setGroupCaptain(tgb.getGroupCaptain());
                    jg.setGroupJoinPeople(tgb.getGroupJoinPeople());
                    jg.setGroupPeople(tgb.getGroupPeople());
                    jg.setId(tgb.getId());
                    jg.setUserInfo(accountManager.getInfo(tgb.getGroupCaptain()));
                    jsonGroupList.add(jg);
                }
                rule.setGroup(jsonGroupList);

                //sku
                ThSku price = goodsManager.goodsPrice(rule.getGoodsId(), rule.getGoodsFormat());
                if (price == null) {
                    rule.setGoodsOldPrice(1000f); // 原价，float类型
                } else {
                    rule.setGoodsOldPrice((float) price.getPrice()); // 原价，float类型
                }
            }
            RemoteUtil.response(response, rules, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "没有团购");
        }

    }

    public void groupGet(HttpServletRequest request, HttpServletResponse response) {
        if (request.getParameter("groupID") == null
                || Integer.parseInt(request.getParameter("groupID")) < 1) {
            RemoteUtil.response(response, null, -1, "参数错误");
            return;
        }
        ThGroupBuying group = goodsManager.groupBuyingGet(Integer.parseInt(request
                .getParameter("groupID")));
        if (group != null && group.getState() > 0) {
            List<?> orderList = goodsManager.groupByingHistoryGet(group.getId());
            ClientInfo info = null;
            ThJsonGroupDetail groupDetail = new ThJsonGroupDetail();
            List<ThJsonGroupUser> userList = new ArrayList<ThJsonGroupUser>();
            for (int i = 0; i < orderList.size(); i++) {
                Object[] obj = (Object[]) orderList.get(i);
                ThJsonGroupUser jUser = new ThJsonGroupUser();
                info = accountManager.getInfo(Integer.parseInt(obj[0].toString()));
                if (info != null) {
                    jUser.setAvatar(info.getPhoto());
                    jUser.setUserID(info.getUserID());
                    jUser.setUserName(info.getName());
                    jUser.setOrderID(Integer.parseInt(obj[2].toString()));
                    jUser.setJoinDate(TimeUtil.getStringTime(Long.parseLong(obj[1].toString()), 2));
                    userList.add(jUser);
                }
            }
            ThGroupBuyingRules rule = goodsManager
                    .groupBuyingRuleGet(group.getGroupBuyingRulesId());
            groupDetail.setUserInfo(userList);
            groupDetail.setGroup(group);
            groupDetail.setRule(rule);
            Goods goods = goodsManager.goodsDetail(rule.getGoodsId());
            ThSku sku = goodsManager.goodsPrice(rule.getGoodsId(), rule.getGoodsFormat());
            goods.setGoodsOldPrice((float) sku.getMarketPrice());
            goods.setGoodsPrice((float) sku.getPrice());
            goods.setGoodsPicture(GoodsParse.getAllGoodsPicture(goods.getGoodsPicture()));
            groupDetail.setGoods(goods);
            RemoteUtil.response(response, groupDetail, 1, "操作成功");
            return;
        }
        RemoteUtil.response(response, null, -1, "没有指定的团购");
    }

    /**
     * 获取某一级分类下的所有二级分类
     *
     * @param request
     * @param response
     */
    public void getCategoryList(HttpServletRequest request, HttpServletResponse response) {
        String cateId = request.getParameter("cateId");
        List<ThJsonCategory> categorys = goodsManager.getCategoryList(new Integer(cateId));
        if (categorys != null) {
            RemoteUtil.response(response, categorys, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "没有分类");
        }
    }

    // 获取分类树
    public void categoryTreeGet(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("categoryTreeGet begin:" + System.currentTimeMillis());
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());
        int shopId = goodsManager
                .shopIdGet(param.getProvince(), param.getCity(), param.getCounty());
        System.out.println("categoryTreeGet return:" + System.currentTimeMillis());
        if (shopId == 0) {
            RemoteUtil.response(response, null, 0, "无开通店铺");
            return;
        }

        // 取全部店铺的数据
        if (param.getAllShops() == 1) {
            shopId = 0;
        }

        List<ThJsonCateGroup> rootCate = goodsManager.categoryTreeGet(shopId);
        System.out.println("categoryTreeGet end:" + System.currentTimeMillis());
        if (rootCate != null) {
            RemoteUtil.response(response, rootCate, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "没有分类");
        }
    }

    // 获取商家分类
    public void getSubCategory(HttpServletRequest request, HttpServletResponse response) {
        String parentID = request.getParameter("parentID");
        String countyName = request.getParameter("countyID");
        PageUtil page = new PageUtil(Integer.parseInt(request.getParameter("page")));

        BussinessInfo business = goodsManager.getBusinessByCounty(countyName);
        if (business != null) {
            List<ThCategories> cate = goodsManager.getCateListByParentAndBussiness(
                    Integer.parseInt(parentID), business.getCompanyID(), page);
            if (cate != null) {
                RemoteUtil.response(response, cate, 1, "操作成功");
            } else {
                RemoteUtil.response(response, null, -1, "没有分类");
            }
        } else {
            RemoteUtil.response(response, null, -1, "区县没有入驻商家");
        }

    }

    public void getGoodsByCate(HttpServletRequest request, HttpServletResponse response) {
        String rootCateID = request.getParameter("rootCateID");
        String subCateID = request.getParameter("subCateID");
        List goods = null;
        if (rootCateID != null) {
            // 获取根分类下所有二级分类
            List<ThCategories> cateList = goodsManager.getSubCateByRootCate(Integer
                    .parseInt(rootCateID));
            // 组合数组
            List<Integer> cateIDList = new ArrayList<Integer>();
            for (ThCategories cate : cateList) {
                cateIDList.add(cate.getId());
            }
            // 根据二级分类数组获取商品
            goods = goodsManager.getGoodsBySubCates(cateIDList);
        } else if (subCateID != null) {
            goods = goodsManager.getGoodsBySubCate(Integer.parseInt(subCateID));
        }

        if (goods != null) {
            RemoteUtil.response(response, goods, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "没有商品");
        }
    }

    // 获取专题列表
    public void topicsGet(HttpServletRequest request, HttpServletResponse response) {
        GoodsParam param = (GoodsParam) RemoteUtil.request(request, new GoodsParam());

        String categoryIdStr = request.getParameter("categoryId");
        if (categoryIdStr == null) {
            RemoteUtil.response(response, null, -1, "操作失败");
            return;
        }

        int categoryId = Integer.parseInt(categoryIdStr);
        // 将省里面的省/市去掉
        int shopID = goodsManager.getShopID(categoryId, param.getProvince(), param.getCity(),
                param.getCounty());
        if (shopID == 0) {
            RemoteUtil.response(response, null, 0, "无开通店铺");
            return;
        }

        // 取全部店铺的数据
        if (param.getAllShops() == 1) {
            shopID = 0;
        }

        List<ThJsonTopics> list = goodsManager.topicsGet(shopID, categoryId);

        RemoteUtil.response(response, list, 1, "操作成功");
    }

    // 获取专题详情
    public void topicGet(HttpServletRequest request, HttpServletResponse response) {
        if (request.getParameter("topicId") == null) {
            RemoteUtil.response(response, null, -1, "操作失败");
            return;
        }
        int topicId = Integer.parseInt(request.getParameter("topicId"));
        int shopID = Integer.parseInt(request.getParameter("shopID"));

        ThJsonRemoteTopic topic = goodsManager.topicGet(topicId, shopID);

        RemoteUtil.response(response, topic, 1, "操作成功");
    }

    public void imgManager(HttpServletRequest request, HttpServletResponse response) {
        goodsManager.compareImg();
        RemoteUtil.response(response, null, 1, "返回成功");
    }

    public void compressImage(HttpServletRequest request, HttpServletResponse response) {
        int currentPage = 331;
        boolean continute = true;
        PageUtil page = new PageUtil(currentPage);
        boolean success = true;
        while (continute) {
            List<String> list = goodsManager.getAllImages(page);
            for (int i = 0; i < list.size(); i++) {
                double quantity = 0.5;
                String path = Path.webappsPath + list.get(i);
                success = ImgUtil.compressImage(path, quantity);
                if (!success) {
                    break;
                }
                System.out.println("已完成第" + currentPage + "页， 第" + i + "项, 文件名:" + list.get(i));
            }
            if (!success) {
                break;
            }
            if (list.size() < 20) {
                continute = false;
            }
            currentPage++;
            page.setCur_page(currentPage);
        }
        if (success) {
            RemoteUtil.response(response, null, 1, "success");
        } else {
            RemoteUtil.response(response, null, -1, "failure");
        }
    }

    public void getPlatformTopics(HttpServletRequest request, HttpServletResponse response) {
        String topicsType = request.getParameter("topicsType");
        if (topicsType == null) {
            topicsType = "-1";
        }

        String state = request.getParameter("state");
        if (state == null) {
            state = "-1";
        }

        String startTime = request.getParameter("startTime");
        if (startTime == null) {
            startTime = "-1";
        }

        String endTime = request.getParameter("endTime");
        if (endTime == null) {
            endTime = "-1";
        }

        String strPage = request.getParameter("page");
        PageUtil page = null;
        if (strPage == null) {
            page = new PageUtil(1);
        } else {
            page = new PageUtil(Integer.parseInt(strPage));
        }
        String strNumPerPage = request.getParameter("numPerPage");
        if (strNumPerPage != null) {
            page.setNumPerPage(Integer.parseInt(strNumPerPage));
        }

        //平台的shopID
        int shopId = 0;
        /*String shopIDStr = request.getParameter("shopID");
        if (!StringUtils.isBlank(shopIDStr)) {
            shopId = new Integer(shopIDStr);
        }*/
        List<Integer> topicsId = new ArrayList<Integer>();
        List<?> list = goodsManager.getTopics(topicsType, shopId, state, startTime, endTime, page);
        Date now = new Date(System.currentTimeMillis());
        Iterator<?> iterator = list.iterator();
        while (iterator.hasNext()) {
            ThTopics topic = (ThTopics) iterator.next();
            topic.setImage(Path.getPathBy(PathType.TOPIC_IMAGE_GET_PATH) + topic.getImage());
            if (!topic.getEndAt().after(now) && topic.getState() == 1) {
                topicsId.add(topic.getId());
                if (state.equals("1")) {
                    iterator.remove();
                }
            }
        }
        Map<String, List<?>> topicMap = new HashMap<String, List<?>>();
        topicMap.put("topicList", list);
        RemoteUtil.response(response, topicMap, 1, "返回成功");

        for (int i : topicsId) {
            goodsManager.updateTopicState(2, i);
        }
    }

    public void pressureTest(HttpServletRequest request, HttpServletResponse response) {

        int i = 3;
        while (i < 57) {
            String path = "/Users/hecong/Desktop/image/IMG_1463的副本 5.jpg";
            if (!ImgUtil.compressImage(path, 0.5)) {
                System.out.println(i);
                break;
            } else {
                i++;
            }
        }
    }

    public static void main(String[] args) {
        double price = 19.9;
        //int a = (int) (price * 100);
        System.out.println(price * 100);
    }

    /**
     * @param directSupplyGoodsManager the directSupplyGoodsManager to set
     */
    public void setDirectSupplyGoodsManager(DirectSupplyGoodsManager directSupplyGoodsManager) {
        this.directSupplyGoodsManager = directSupplyGoodsManager;
    }

    public DirectSupplyManager getDirectSupplyManager() {
        return directSupplyManager;
    }

    public void setDirectSupplyManager(DirectSupplyManager directSupplyManager) {
        this.directSupplyManager = directSupplyManager;
    }

    private AccountManager accountManager;

    public AccountManager getAccountManager() {
        return accountManager;
    }

    public void setAccountManager(AccountManager accountManager) {
        this.accountManager = accountManager;
    }

    /**
     * Gets the logi manager.
     *
     * @return the logi manager
     */
    public LogisticManager getLogiManager() {
        return logiManager;
    }

    /**
     * Sets the logi manager.
     *
     * @param logiManager the new logi manager
     */
    public void setLogiManager(LogisticManager logiManager) {
        this.logiManager = logiManager;
    }

    /**
     * Gets the goods manager.
     *
     * @return the goods manager
     */
    public GoodsManager getGoodsManager() {
        return goodsManager;
    }

    /**
     * Sets the goods manager.
     *
     * @param goodsManager the new goods manager
     */
    public void setGoodsManager(GoodsManager goodsManager) {
        this.goodsManager = goodsManager;
    }
}
